package com.example.demo.suanfa_2tree;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 层序 从左向右输出 结构
 */
public class LevelTraversalBTDemo {

    class Node {
        int value;
        Node left;
        Node right;
    }

    public void levelOut(Node node){
        if (node == null){
            return;
        }
        Queue<Node> queue = new LinkedList<>();
        queue.add(node);
        while (!queue.isEmpty()){
            Node poll = queue.poll();
            System.out.println(poll.value);
            if (poll.left!=null){
                queue.add(poll.left);
            }
            if (poll.right!=null){
                queue.add(poll.right);
            }
        }
    }




}
